//
//  DSWebViewController.m
//  DSJY
//
//  Created by 冯华强 on 16/10/30.
//  Copyright © 2016年 dsjy. All rights reserved.
//

#import "DSWebViewController.h"
#import "Masonry.h"

@interface DSWebViewController ()
@property (nonatomic, strong) UIWebView *webView;
@end

@implementation DSWebViewController

#pragma mark - 懒加载
- (UIWebView *)webView
{
    if (_webView == nil) {
        UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectZero];
        [self.view addSubview:webView];
        _webView = webView;
        
        [webView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsZero);
        }];
    }
    return _webView;
}

#pragma mark - 系统回调
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //显示backItem
    [self setupnavigationItem];
    
    //设置UI
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)viewWillAppear:(BOOL)animated
{
    
    [super viewWillAppear:animated];
    
    //加载html
    [self loadPage:self.webView];
}

#pragma mark - 设置UI
- (void)setupnavigationItem
{
    self.showBackItem = YES;
}

- (void)loadPage:(UIWebView *)webView
{
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:self.filePath ofType:@"html"];
    NSString *appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
    NSURL *baseURL = [NSURL fileURLWithPath:htmlPath];
    [webView loadHTMLString:appHtml baseURL:baseURL];
}

@end
